"""
下面的文件将会从csv文件中读取读取短信与电话记录，
你将在以后的课程中了解更多有关读取文件的知识。
"""
import csv

with open('texts.csv', 'r') as f:
    reader = csv.reader(f)
    texts = list(reader)

with open('calls.csv', 'r') as f:
    reader = csv.reader(f)
    calls = list(reader)

"""
任务4:
电话公司希望辨认出可能正在用于进行电话推销的电话号码。
找出所有可能的电话推销员:
这样的电话总是向其他人拨出电话，
但从来不发短信、接收短信或是收到来电


请输出如下内容
"These numbers could be telemarketers: "
<list of numbers>
电话号码不能重复，每行打印一条，按字典顺序排序后输出。
"""

def select_tele(n, records):
    tele_list = []
    for record in records:
        if record[n][:3] == "140":
            if record[n] not in tele_list:
                tele_list.append(record[n])
    return tele_list


def select_sale_tele():
    calling_tele = select_tele(0, calls) #主叫号码,疑似促销号码
    called_tele = select_tele(1, calls)
    texting_tele = select_tele(0, texts)
    texted_tele = select_tele(1, texts)

    other_tele = called_tele + texting_tele + texted_tele

    for item in calling_tele:
        if item in other_tele:
            calling_tele.remove(item)

    calling_tele = sorted(calling_tele, key = lambda x : x)
    # for item in calling_tele:
    #     print("These numbers could be telemarketers: {}".format(item))
    print("These numbers could be telemarketers: {}".format(calling_tele))

select_sale_tele()
